package backend.login;

import java.util.Map;

import backend.user.manager.UserManager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import core.profile.model.BasicProfile;
//import core.role.model.BasicRoles;
import frontend.registration.dao.RegisterDao;

public class LoginAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 118112323324238757L;
	private String userId;
	private String password;
	private BasicProfile user;
	//private Set<BasicRoles> roleid;
	private Integer usertype;
	private RegisterDao registerdao=new RegisterDao();
	private UserManager um;
	public LoginAction()
	{
		um=new UserManager();
	}
	public String execute() throws Exception{
	
		user=um.getUserUserId(userId);
		//roleid=user.getBasicRoles();
		if (registerdao.getAdminUser(userId,password)) {
			Map<String, Object> session = ActionContext.getContext().getSession();
			session.put("logined","true");
			session.put("emailId", userId);
            return SUCCESS;
        }
		else{
			 return ERROR;
		}
    }

    public String logout() throws Exception {

		Map<?, ?> session = ActionContext.getContext().getSession();
		session.remove("logined");
		session.remove("emailId");
        return SUCCESS;
    }
    
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

	public Integer getUsertype() {
		return usertype;
	}

	public void setUsertype(Integer usertype) {
		this.usertype = usertype;
	}
	public BasicProfile getUser() {
		return user;
	}
	public void setUser(BasicProfile user) {
		this.user = user;
	}
    
}